package com.android.test.activity;

import com.android.test.R;
import com.android.test.util.GlobalUtil;
import com.android.test.util.OptionsMenu;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;

public class MainEntryActivity extends Activity {
    @SuppressWarnings("unused")
    private final static String TAG = MainEntryActivity.class.getSimpleName();

    private final String KeyName = "subject";



    private int mKeyBackCount = 0;

    private ImageButton mImageBtn = null;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFormat(1);
        setContentView(R.layout.activity_home);
        mImageBtn = (ImageButton) findViewById(R.id.topbar_search);
        mImageBtn.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                onSearchClick();
            }

        });
    }

    public void onResume() {
        super.onResume();
        mKeyBackCount = 0;
    }

    @Override
    public boolean dispatchKeyEvent(KeyEvent event) {
        if (event.getAction() == KeyEvent.ACTION_DOWN) {
            switch (event.getKeyCode()) {
                case KeyEvent.KEYCODE_BACK: {

                    if (mKeyBackCount == 0) {
                        mKeyBackCount++;
                        GlobalUtil.shortToast(this, R.string.exit_hint_msg);
                    } else {
                        finish();
                    }
                    return true;
                }
            }
        }

        return super.dispatchKeyEvent(event);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        OptionsMenu.onCreateOptionsMenu(menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        OptionsMenu.onOptionsItemSelected(this, item);
        return super.onOptionsItemSelected(item);
    }

    public void onScoreClick(View v) {
        Intent intent = new Intent();
        intent.setClass(this, TestResultActivity.class);
        startActivity(intent);
    }

    public void onProfileClick(View v) {
        Intent intent = new Intent();
        intent.setClass(this, MenuProfileActivity.class);
        startActivity(intent);
    }

    public void onChineseClick(View paramView) {
        Intent localIntent = new Intent(this, SubjectStudyActivity.class);
        startActivity(localIntent);
    }

    public void onMathClick(View paramView)
    {
      Intent localIntent = new Intent(this, MathStudyActivity.class);
      startActivity(localIntent);
    }

    public void onEnglishClick(View paramView) {
        // Intent localIntent = new Intent(this, SubjectStudyActivity.class);
        // localIntent.putExtra(KeyName,valueEnglish);
        // startActivity(localIntent);
    }

    public void onSyntheticClick(View paramView) {
        // Intent localIntent = new Intent(this, SubjectStudyActivity.class);
        // localIntent.putExtra(KeyName,valueSynthetic);
        // startActivity(localIntent);
    }

    public void onSettingClick(View paramView) {
        Intent localIntent = new Intent(this, MenuSettingActivity.class);
        startActivity(localIntent);
    }

    public void onHelpClick(View paramView) {
        Intent localIntent = new Intent(this, HelpActivity.class);
        startActivity(localIntent);
    }

    private void onSearchClick() {
        Intent localIntent = new Intent(this, SearchActivity.class);
        startActivity(localIntent);
    }

}